package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.QueryMemberInfoBySourceBean;
import com.shop2cn.iapi.member.service.QueryMemberInfoBySourceCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据手机号查询电铺会员
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryMemberInfoBySource{
	private static QueryMemberInfoBySourceBean QueryMemberInfoBySourceBean;
	private static QueryMemberInfoBySourceCall QueryMemberInfoBySourceCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userId查手机号，然后根据手机号找到会员信息在帅选来源");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		QueryMemberInfoBySourceBean=new QueryMemberInfoBySourceBean();
		QueryMemberInfoBySourceCall=new QueryMemberInfoBySourceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(QueryMemberInfoBySourceCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_001() {
		Logger.start(true,"根据userId查手机号，然后根据手机号找到最老的会员信息-查询appsource0");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setAccessSource(0);
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			QueryMemberInfoBySourceBean.setAppSource(0);
			QueryMemberInfoBySourceBean.setUserId(userId);
			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			Logger.verifyEquals(usercreateBean.getOpenId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getOpenId(), "验证openid");
			Logger.verifyEquals(createMem.getAccessSource(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getAppSource(), "验证getAppSource");
			Logger.verifyEquals(mobile, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getMobile(), "验证openid");
			Logger.verifyEquals(createMem.getShopId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getShopId(), "验证getShopId");
			Logger.verifyEquals(userId, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getUserId(), "验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			QueryMemberInfoBySourceBean.setAppSource(1);
			QueryMemberInfoBySourceBean.setUserId(1);
//			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("400", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_003() {
		Logger.start(true,"不输入userid失败");
		try {
			QueryMemberInfoBySourceBean.setAppSource(1);
//			QueryMemberInfoBySourceBean.setMobile("13712163581");
			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("400", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_004() {
		Logger.start(true,"不输入AppSource失败");
		try {
//			QueryMemberInfoBySourceBean.setAppSource(1);
			QueryMemberInfoBySourceBean.setUserId(1);
			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_005() {
		Logger.start(true,"根据userId查手机号，然后根据手机号找到最老的会员信息-查询appsource");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setAccessSource(1);
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			QueryMemberInfoBySourceBean.setAppSource(1);
			QueryMemberInfoBySourceBean.setUserId(userId);
			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			Logger.verifyEquals(usercreateBean.getOpenId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getOpenId(), "验证openid");
			Logger.verifyEquals(createMem.getAccessSource(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getAppSource(), "验证getAppSource");
			Logger.verifyEquals(mobile, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getMobile(), "验证openid");
			Logger.verifyEquals(createMem.getShopId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getShopId(), "验证getShopId");
			Logger.verifyEquals(userId, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getUserId(), "验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_006() {
		Logger.start(true,"根据userId查手机号，然后根据手机号找到最老的会员信息-appsource不匹配失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setAccessSource(1);
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			QueryMemberInfoBySourceBean.setAppSource(0);
			QueryMemberInfoBySourceBean.setUserId(userId);
			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			Logger.verifyEquals(null, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource(), "验证结果");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberInfoBySource_007() {
		Logger.start(true,"根据userId查手机号，然后根据手机号找到最老的会员信息-查询appsource-2个渠道都绑定了手机");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setAccessSource(0);
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			
			
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			createMem2.setAccessSource(1);
			String memid2 = GodMemberService.creatememberCall(createMem2);
			GodMemberService.bindMobile(shopid, userId2, mobile);
			
			QueryMemberInfoBySourceBean.setAppSource(0);
			QueryMemberInfoBySourceBean.setUserId(userId);
			QueryMemberInfoBySourceBean.setShopId(shopid);
			QueryMemberInfoBySourceCall.setData(QueryMemberInfoBySourceBean);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			Logger.verifyEquals(usercreateBean.getOpenId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getOpenId(), "验证openid");
			Logger.verifyEquals(createMem.getAccessSource(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getAppSource(), "验证getAppSource");
			Logger.verifyEquals(mobile, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getMobile(), "验证openid");
			Logger.verifyEquals(createMem.getShopId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getShopId(), "验证getShopId");
			Logger.verifyEquals(userId, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getUserId(), "验证userid");
			
			QueryMemberInfoBySourceBean.setAppSource(1);
			QueryMemberInfoBySourceCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoBySourceCall.getString("code"), "验证code");
			Logger.verifyEquals(usercreateBean2.getOpenId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getOpenId(), "验证openid");
			Logger.verifyEquals(createMem2.getAccessSource(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getAppSource(), "验证getAppSource");
			Logger.verifyEquals(mobile, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getMobile(), "验证openid");
			Logger.verifyEquals(createMem2.getShopId(), QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getShopId(), "验证getShopId");
			Logger.verifyEquals(userId2, QueryMemberInfoBySourceCall.getQueryMemberInfoBySource().getUserId(), "验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}